package com.project_test.kun.travelling_1st.Butler;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.project_test.kun.travelling_1st.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/10/18.
 */
public class ButlerAdapter extends BaseAdapter {

    private List<Butler.DataBean.ListBean> data;
    private Context context;
    ViewHolder viewHolder=null;

    public ButlerAdapter(List<Butler.DataBean.ListBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data!=null?data.size():0;
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        View  ret=view;

        if (ret==null){
            ret= LayoutInflater.from(context).inflate(R.layout.item_list,viewGroup,false);
            viewHolder=new ViewHolder();
            viewHolder.showImg= (ImageView) ret.findViewById(R.id.showImg);
            viewHolder.title= (TextView) ret.findViewById(R.id.title);
            viewHolder.titleDown= (TextView) ret.findViewById(R.id.title_down);
            viewHolder.price= (TextView) ret.findViewById(R.id.price);
            viewHolder.first= (ImageView) ret.findViewById(R.id.first);
            viewHolder.second= (ImageView) ret.findViewById(R.id.second);
            viewHolder.third= (ImageView) ret.findViewById(R.id.third);
            viewHolder.forth= (ImageView) ret.findViewById(R.id.forth);
            viewHolder.fifth= (ImageView) ret.findViewById(R.id.fifth);
            ret.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) view.getTag();
        }
        Butler.DataBean.ListBean listBean = data.get(i);
        viewHolder.title.setText(listBean.getTitle());
        viewHolder.price.setText(listBean.getPrice());
        viewHolder.titleDown.setText(listBean.getService_type_name());
        Picasso.with(context).load(listBean.getHead_pic()).into(viewHolder.showImg);
        String scores = listBean.getScores() ;
        switch (scores) {
            case "5.00":
                viewHolder.fifth.setImageResource(R.mipmap.icon_ratingbar);
                viewHolder.forth.setImageResource(R.mipmap.icon_ratingbar);
                viewHolder.third.setImageResource(R.mipmap.icon_ratingbar);
                viewHolder.second.setImageResource(R.mipmap.icon_ratingbar);
                viewHolder.first.setImageResource(R.mipmap.icon_ratingbar);
                break;
            case "4.00":
                viewHolder.forth.setImageResource(R.mipmap.icon_ratingbar);
                viewHolder.third.setImageResource(R.mipmap.icon_ratingbar);
                viewHolder.second.setImageResource(R.mipmap.icon_ratingbar);
                viewHolder.first.setImageResource(R.mipmap.icon_ratingbar);
                break;
            case "3.00":
                viewHolder.third.setImageResource(R.mipmap.icon_ratingbar);
                viewHolder.second.setImageResource(R.mipmap.icon_ratingbar);
                viewHolder.first.setImageResource(R.mipmap.icon_ratingbar);
                break;
            case "2.00":
            viewHolder.second.setImageResource(R.mipmap.icon_ratingbar);
            viewHolder.first.setImageResource(R.mipmap.icon_ratingbar);
                break;
            case "1.00":
                viewHolder.first.setImageResource(R.mipmap.icon_ratingbar);
                break;
        }
        return ret;
    }
    class ViewHolder {
        ImageView showImg,first,second,third,forth,fifth;
        TextView title,titleDown,price;
    }
}
